package com.cet.billingjob.jobs;

import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.JobParametersValidator;
import org.springframework.stereotype.Component;

import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author 30952
 */
@Component
public class FileParameterValidator implements JobParametersValidator {
    @Override
    public void validate(JobParameters parameters) throws JobParametersInvalidException {
        String inputFile = parameters.getString("input.file");
        if (inputFile != null && !Files.exists(Paths.get(inputFile))) {
            throw new JobParametersInvalidException("input file path is invalid!");
        }
    }
}
